﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommerceOne.Domains.Repositories;
using CommerceOne.Domains.SqlRepositories;
using CommerceOne.Models;
using CommerceOne.Widgets.PagingAndSortingNav;

namespace CommerceOne.Controllers
{
    public class BrandController : ControllerBase
    {
        private readonly IProductRepository _productRepository = new SqlProductRepository();
        private readonly IBrandRepository _brandRepository = new SqlBrandRepository();

        /// <summary>
        /// Indexes the specified object id.
        /// </summary>
        /// <param name="objectId">The object id.</param>
        /// <param name="page">The page.</param>
        /// <returns></returns>
        public ActionResult Index(int objectId, int page)
        {
            BrandViewModel viewModel = new BrandViewModel();
            this.CommonInitialize(viewModel);

            int size = 3;
            int totalRecord = this._productRepository.GetTotalByBrand(objectId);

            PagingSortingNavController pagingSortingController = new PagingSortingNavController();
            viewModel.PagingSortingViewModel = pagingSortingController.GetViewModel(totalRecord, size, page, "/" + objectId + "/Brand/{0}");
            viewModel.BrandProductList = this._productRepository.GetTotalBrand(objectId, page, size);

            viewModel.CurrentBrand = this._brandRepository.GetById(objectId);

            return View(viewModel);
        }

        /// <summary>
        /// Alls the brand.
        /// </summary>
        /// <returns></returns>
        public ActionResult AllBrand()
        {
            AllBrandViewModel viewModel = new AllBrandViewModel();
            this.CommonInitialize(viewModel);
            viewModel.AllBrandList = this._brandRepository.GetAll();
            return View(viewModel);
        }

    }
}
